package com.gupaoedu.demo.serialize;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 * <p>
 *
 * </p>
 *
 * @author Nicky
 * @since 2019-07-23
 */
public class XStreamSerializer implements ISerialize {

    private XStream xStream = new XStream(new DomDriver());

    @Override
    public <T> byte[] serialize(T object) {
        return xStream.toXML(object).getBytes();
    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> claz) {
        return (T)xStream.fromXML(new String(bytes));
    }
}
